package com.bidepan.validation.one;

import org.springframework.validation.BindingResult;
import org.springframework.validation.DataBinder;
//
// 通过实现validator接口实现数据校验
//
public class TestPerson {
    public static void main(String[] args){
        //创建Person对象
        Person person = new Person();
        person.setName("John");
        person.setAge(-1);
        //创建Databinder绑定器
        DataBinder databinder = new DataBinder(person);
        //设置校验器
        databinder.setValidator(new PersonValidator());
        //调用方法执行校验
        databinder.validate();
        //输出校验结果
        BindingResult result = databinder.getBindingResult();
        System.out.println(result.getAllErrors());
    }
}
